﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Web;
using CrystalDecisions.Windows;

namespace QLThuoc_report
{
    public partial class Frm_TkeThuocNhap_Thang2 : Form
    {
        public Frm_TkeThuocNhap_Thang2()
        {
            InitializeComponent();
        }
        private int _Thang;

        public int Thang
        {
            get { return _Thang; }
            set { _Thang = value; }
        }
        private int _Nam;

        public int Nam
        {
            get { return _Nam; }
            set { _Nam = value; }
        }


        private void Frm_TkeThuocNhap_Thang2_Load(object sender, EventArgs e)
        {
           SqlConnection conn = new SqlConnection("Data Source =(local);Initial Catalog=QLThuoc;Integrated Security=true");
           SqlDataAdapter da = new SqlDataAdapter("SELECT     dbo.tbl_Thuoc.TenThuoc AS 'Tên Thuốc', SUM(dbo.tbl_CTHoaDonNhap.SoLuong) AS 'Số Lượng Đã Nhập', dbo.tbl_CTHoaDonNhap.GiaNhap AS 'Giá Nhập',   SUM(dbo.tbl_CTHoaDonNhap.SoLuong * dbo.tbl_Thuoc.GiaTien) AS 'Tổng Tiền' FROM         dbo.tbl_CTHoaDonNhap INNER JOIN   dbo.tbl_Thuoc ON dbo.tbl_CTHoaDonNhap.MaThuoc = dbo.tbl_Thuoc.MaThuoc where Month( tbl_CTHoaDonNhap.NgaySX) ='" + Thang + "' and year(tbl_CTHoaDonNhap.NgaySX)='" + Nam + "' GROUP BY dbo.tbl_Thuoc.TenThuoc, MONTH(dbo.tbl_CTHoaDonNhap.NgaySX), YEAR(dbo.tbl_CTHoaDonNhap.NgaySX), dbo.tbl_CTHoaDonNhap.GiaNhap  ", conn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            //lay duong dan du chuy?n sang máy tính nào c?ng ko b? l?i, ko có c?ng ðc nhýng sang máy tính khác s? ko ch?y ðc
            string path = Application.StartupPath;
            path = path.Substring(0, path.LastIndexOf("bin")) + "TKeThuocTheoThang2.rpt";
            TKeThuocTheoThang2 report = new TKeThuocTheoThang2();
            report.SetDataSource(dt);
            crystalReportViewer1.ReportSource = report;
        }
    }
}
